package com.gdones.wms.core.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 模块名称： Swagger模板配置
 * 模块类型：
 * 编码人：高靖博
 * 创建时间：2023/3/18
 * 联系电话：18587388612
 */

@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class Swagger2Config implements WebMvcConfigurer {

    // 配置文档描述、扫描注解的配置
    public Docket createRestApi(){

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo()) // 配置文档描述方法
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.gdones.bootserver"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("GDonesCloudBoot-WMS-项目API文档")
                .description("2023-4-25 建立")
                .termsOfServiceUrl("http://localhost:8100")
                .contact("作者：高靖博 邮箱：760662328@qq.com")
                .version("v1.0")
                .build();
    }


    /**
     * 添加swaggerui资源到spring
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:META-INF/resources/");
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:META-INF/resources/webjars/");
    }
}
